// pages/login/selection-center.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role_id: 0,
    site:'',
    business_id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let token = wx.getStorageSync('token')
    let role_id = wx.getStorageSync('role_id')
    let url = wx.getStorageSync('urlR')
    let site = wx.getStorageSync('site')
    let business_id = wx.getStorageSync('business_id')
    
    url = `/${url}`
    // console.log(token);
    if (token == null || token == undefined || token == '') {
      wx.redirectTo({
        url: '../login/login',
      })
    } else if (role_id == 7 && token && url != '/pages/login/login') {
      wx.switchTab({
        url,
      })
    }
    this.setData({
      role_id: role_id,
      site:site,
      business_id:business_id
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //删除带看
  select(e) {
    let _this = this
    let type = e.currentTarget.dataset.type
    //销售端
    if (type == 1) {
      if (_this.data.role_id == 9 || _this.data.role_id == 12 || _this.data.role_id == 23  || _this.data.site=='demo_site') {
        wx.reLaunch({
          url: '../manager-source/personal'
        })
      } else {
        wx.switchTab({
          url: '../index/index'
        })
      }
    }

    //运营
    if (type == 2) {

      if(_this.data.role_id == 18){
        wx.reLaunch({
          url: '../../packageA/pages/franchisee/index/secondindex'
        })
      }else{
        wx.reLaunch({
          url: '../../packageA/pages/franchisee/index/index'
        })
      }
    }
    //加盟商
    if (type == 3) {
      if(_this.data.role_id == 22){
        wx.reLaunch({
          url: '../../packageA/pages/operate/index/secondindex'
        })
      }else{
        wx.reLaunch({
          url: '../../packageA/pages/operate/index/index'
        })
      }
    }
  },
  select1(){
    wx.switchTab({
      url: '../index/index'
    })
  },
  select2(){
    console.log(2222)
    wx.reLaunch({
      url: '../../packageB/pages/human/index/index'
    })
  }
})